home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / blanker / source / blankers / flyingtoaster / flyingtoaster.c < prev    next >
C/C++ Source or Header  |  1993-07-11  |  7KB  |  241 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Michael D. Bayne
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <string.h>
  23. #include <clib/diskfont_protos.h>
  24.  
  25. #include "FlyingToaster.h"
  26.  
  27. struct Screen         *Scr = NULL;
  28. UBYTE                 *PubScreenName = "Workbench";
  29. APTR                   VisualInfo = NULL;
  30. struct Window         *FlyingToasterWnd = NULL;
  31. struct Gadget         *FlyingToasterGList = NULL;
  32. struct IntuiMessage    FlyingToasterMsg;
  33. struct Gadget         *FlyingToasterGadgets[5];
  34. UWORD                  FlyingToasterLeft = 0;
  35. UWORD                  FlyingToasterTop = 11;
  36. UWORD                  FlyingToasterWidth = 359;
  37. UWORD                  FlyingToasterHeight = 47;
  38. UBYTE                 *FlyingToasterWdt = (UBYTE *)"Flying Toaster Prefs";
  39. struct TextAttr       *Font, Attr;
  40. UWORD                  FontX, FontY;
  41. UWORD                  OffX, OffY;
  42. struct TextFont       *FlyingToasterFont = NULL;
  43.  
  44. UWORD FlyingToasterGTypes[] = {
  45.     SLIDER_KIND,
  46.     BUTTON_KIND,
  47.     BUTTON_KIND,
  48.     SLIDER_KIND,
  49.     BUTTON_KIND
  50. };
  51.  
  52. struct NewGadget FlyingToasterNGad[] = {
  53.     77, 2, 224, 12, (UBYTE *)"_Objects", NULL, GD_OBJECTS, PLACETEXT_LEFT, NULL, (APTR)OBJECTSClicked,
  54.     10, 32, 88, 12, (UBYTE *)"_Ok", NULL, GD_OK, PLACETEXT_IN, NULL, (APTR)OKClicked,
  55.     259, 32, 88, 12, (UBYTE *)"_Cancel", NULL, GD_CANCEL, PLACETEXT_IN, NULL, (APTR)CANCELClicked,
  56.     77, 17, 224, 12, (UBYTE *)"_Speed", NULL, GD_SPEED, PLACETEXT_LEFT, NULL, (APTR)SPEEDClicked,
  57.     134, 32, 88, 12, (UBYTE *)"_Test", NULL, GD_TEST, PLACETEXT_IN, NULL, (APTR)TESTClicked
  58. };
  59.  
  60. ULONG FlyingToasterGTags[] = {
  61.     (GTSL_Min), 1, (GTSL_Max), 40, (GTSL_Level), 3, (GTSL_MaxLevelLen), 6, (GTSL_LevelFormat), (ULONG)"%3ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
  62.     (GT_Underscore), '_', (TAG_DONE),
  63.     (GT_Underscore), '_', (TAG_DONE),
  64.     (GTSL_Min), 1, (GTSL_Max), 3, (GTSL_Level), 16, (GTSL_MaxLevelLen), 4, (GTSL_LevelFormat), (ULONG)"%3ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
  65.     (GT_Underscore), '_', (TAG_DONE)
  66. };
  67.  
  68. static UWORD ComputeX( UWORD value )
  69. {
  70.     return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
  71. }
  72.  
  73. static UWORD ComputeY( UWORD value )
  74. {
  75.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  76. }
  77.  
  78. static void ComputeFont( UWORD width, UWORD height )
  79. {
  80.     Forbid();
  81.     Font = &Attr;
  82.     Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  83.     Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
  84.     FontX = GfxBase->DefaultFont->tf_XSize;
  85.     Permit();
  86.  
  87.     OffX = Scr->WBorLeft;
  88.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  89.  
  90.     if ( width && height ) {
  91.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  92.             goto UseTopaz;
  93.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  94.             goto UseTopaz;
  95.     }
  96.     return;
  97.  
  98. UseTopaz:
  99.     Font->ta_Name = (STRPTR)"topaz.font";
  100.     FontX = FontY = Font->ta_YSize = 8;
  101. }
  102.  
  103. int SetupScreen( void )
  104. {
  105.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  106.         return( 1L );
  107.  
  108.     ComputeFont( 0, 0 );
  109.  
  110.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  111.         return( 2L );
  112.  
  113.     return( 0L );
  114. }
  115.  
  116. void CloseDownScreen( void )
  117. {
  118.     if ( VisualInfo ) {
  119.         FreeVisualInfo( VisualInfo );
  120.         VisualInfo = NULL;
  121.     }
  122.  
  123.     if ( Scr        ) {
  124.         UnlockPubScreen( NULL, Scr );
  125.         Scr = NULL;
  126.     }
  127. }
  128.  
  129. int HandleFlyingToasterIDCMP( void )
  130. {
  131.     struct IntuiMessage    *m;
  132.     int            (*func)();
  133.     BOOL            running = TRUE;
  134.  
  135.     while( m = GT_GetIMsg( FlyingToasterWnd->UserPort )) {
  136.  
  137.         CopyMem(( char * )m, ( char * )&FlyingToasterMsg, (long)sizeof( struct IntuiMessage ));
  138.  
  139.         GT_ReplyIMsg( m );
  140.  
  141.         switch ( FlyingToasterMsg.Class ) {
  142.  
  143.             case    IDCMP_REFRESHWINDOW:
  144.                 GT_BeginRefresh( FlyingToasterWnd );
  145.                 GT_EndRefresh( FlyingToasterWnd, TRUE );
  146.                 break;
  147.  
  148.             case    IDCMP_VANILLAKEY:
  149.                 running = FlyingToasterVanillaKey();
  150.                 break;
  151.  
  152.             case    IDCMP_GADGETUP:
  153.             case    IDCMP_GADGETDOWN:
  154.                 func = ( void * )(( struct Gadget * )FlyingToasterMsg.IAddress )->UserData;
  155.                 running = func();
  156.                 break;
  157.         }
  158.     }
  159.     return( running );
  160. }
  161.  
  162. int OpenFlyingToasterWindow( void )
  163. {
  164.     struct NewGadget    ng;
  165.     struct Gadget    *g;
  166.     UWORD        lc, tc;
  167.     UWORD        wleft = FlyingToasterLeft, wtop = FlyingToasterTop, ww, wh;
  168.  
  169.     ComputeFont( FlyingToasterWidth, FlyingToasterHeight );
  170.  
  171.     ww = ComputeX( FlyingToasterWidth );
  172.     wh = ComputeY( FlyingToasterHeight );
  173.  
  174.     wleft = ( Scr->Width - ww )/2 - Scr->WBorRight;
  175.     wtop = ( Scr->Height - wh - Font->ta_YSize )/2 - Scr->WBorBottom;
  176.  
  177.     if ( ! ( FlyingToasterFont = OpenDiskFont( Font )))
  178.         return( 5L );
  179.  
  180.     if ( ! ( g = CreateContext( &FlyingToasterGList )))
  181.         return( 1L );
  182.  
  183.     for( lc = 0, tc = 0; lc < FlyingToaster_CNT; lc++ ) {
  184.  
  185.         CopyMem((char * )&FlyingToasterNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  186.  
  187.         ng.ng_VisualInfo = VisualInfo;
  188.         ng.ng_TextAttr   = Font;
  189.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  190.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  191.         ng.ng_Width      = ComputeX( ng.ng_Width );
  192.         ng.ng_Height     = ComputeY( ng.ng_Height);
  193.  
  194.         FlyingToasterGadgets[ lc ] = g = CreateGadgetA((ULONG)FlyingToasterGTypes[ lc ], g, &ng, ( struct TagItem * )&FlyingToasterGTags[ tc ] );
  195.  
  196.         while( FlyingToasterGTags[ tc ] ) tc += 2;
  197.         tc++;
  198.  
  199.         if ( NOT g )
  200.             return( 2L );
  201.     }
  202.  
  203.     if ( ! ( FlyingToasterWnd = OpenWindowTags( NULL,
  204.                 WA_Left,    wleft,
  205.                 WA_Top,        wtop,
  206.                 WA_Width,    ww + OffX + Scr->WBorRight,
  207.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  208.                 WA_IDCMP,    SLIDERIDCMP|BUTTONIDCMP|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  209.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP,
  210.                 WA_Gadgets,    FlyingToasterGList,
  211.                 WA_Title,    FlyingToasterWdt,
  212.                 WA_ScreenTitle,    "Flying Toaster Prefs",
  213.                 WA_AutoAdjust,    TRUE,
  214.                 WA_PubScreenFallBack,    TRUE,
  215.                 TAG_DONE )))
  216.     return( 4L );
  217.  
  218.     GT_RefreshWindow( FlyingToasterWnd, NULL );
  219.  
  220.     return( 0L );
  221. }
  222.  
  223. void CloseFlyingToasterWindow( void )
  224. {
  225.     if ( FlyingToasterWnd        ) {
  226.         CloseWindow( FlyingToasterWnd );
  227.         FlyingToasterWnd = NULL;
  228.     }
  229.  
  230.     if ( FlyingToasterGList      ) {
  231.         FreeGadgets( FlyingToasterGList );
  232.         FlyingToasterGList = NULL;
  233.     }
  234.  
  235.     if ( FlyingToasterFont ) {
  236.         CloseFont( FlyingToasterFont );
  237.         FlyingToasterFont = NULL;
  238.     }
  239. }
  240.  
  241.